//
//  RequestDataTool.m
//  KaiXinDa
//
//  Created by stonesMonkey on 2018/11/23.
//  Copyright © 2018年 stonesMonkey. All rights reserved.
//

#import "RequestDataTool.h"

@implementation RequestDataTool

///1.1打开磁条卡
+ (NSData *)openMagneticCard {
    NSDictionary *dic = @{@"dName":@"CardDevice",@"action":@"openMSR",@"arg1":@(0),@"arg2":@(0),@"param1":@"",@"param2":@"",@"data":@"",@"timeOut":@(0)};
    //将字典转换成十六进制的固定格式字符串
    NSString *hexadecimalStr = [ZYFDataConversionTool hexadecimalToDictionary:dic];
//    NSLog(@"打开磁条卡 \n %@",hexadecimalStr);
    //将十六进制转换成nsdata
    NSData *data = [ZYFDataConversionTool convertHexStrToData:hexadecimalStr];
    
    return data;
}

///1.2检查刷卡
+(NSData *)checkCreditCard:(NSInteger)timeOut {
    

    NSDictionary *dic = @{@"dName":@"CardDevice",@"action":@"checkMSR",@"arg1":@(0),@"arg2":@(0),@"param1":@"",@"param2":@"",@"data":@"",@"timeOut":@(15)};
    NSString *hexadecimalStr = [ZYFDataConversionTool hexadecimalToDictionary:dic];
//    NSLog(@"检查刷卡 \n %@",hexadecimalStr);
    NSData *data = [ZYFDataConversionTool convertHexStrToData:hexadecimalStr];
    return data;
}

///1.3取消刷卡
+(NSData *)cancelCreditCard {
    
    NSDictionary *dic = @{@"dName":@"CardDevice",@"action":@"cancelMSR",@"arg1":@(0),@"arg2":@(0),@"param1":@"",@"param2":@"",@"data":@"",@"timeOut":@(0)};
    NSString *hexadecimalStr = [ZYFDataConversionTool hexadecimalToDictionary:dic];
//    NSLog(@"取消刷卡 \n %@",hexadecimalStr);
    NSData *data = [ZYFDataConversionTool convertHexStrToData:hexadecimalStr];
    return data;
}

///2.1自动检卡
+(NSData *)autoCheckCard:(ResetCardType)slot {
    
    
    //arg1 1磁条 2 IC 4非接 需要多种类型直接相加
    NSDictionary *dic = @{@"dName":@"PBOCDevice",@"action":@"checkCardAuto",@"arg1":@(slot),@"arg2":@(0),@"param1":@"",@"param2":@"",@"data":@"",@"timeOut":@(10)};
    
    NSString *hexadecimalStr = [ZYFDataConversionTool hexadecimalToDictionary:dic];
//    NSLog(@"自动检卡 \n%@",hexadecimalStr);
    NSData *data = [ZYFDataConversionTool convertHexStrToData:hexadecimalStr];
    
    return data;
}

///2.2开启PBOC流程
+(NSData *)startPBOCProcess:(ResetCardType)slot {
    
    NSDictionary *dic = @{
                          @"param2":@"",
                          @"param1":@"",
                          @"action":@"PBOCProcess1",
                          @"data":@"[]",
                          @"dName":@"PBOCDevice",
                          @"arg1":@(slot),
                          @"timeOut":@(0),
                          @"arg2":@(0),
                          };
    
    NSString *hexadecimalStr = [ZYFDataConversionTool hexadecimalToDictionary:dic];
//    NSLog(@"开启PBOC流程 \n %@",hexadecimalStr);
    NSData *data = [ZYFDataConversionTool convertHexStrToData:hexadecimalStr];
    return data;
}

///2.3获取55域（IC卡复位只调用自动检卡)
+(NSData *)obtainDomain55:(ResetCardType)slot {
    
//    NSString *param1 = @"[\n  \"9F77\",\n  \"9F78\",\n  \"9F5C\",\n  \"9F79\"\n]";
//    NSString *param1 = @"[\n  \"9F78\",\n  \"9F77\",\n  \"9F5C\",\n  \"9F59\",\n  \"9F79\",,\n  \"4F\"\n]";
    NSString *param1= @"";
//    NSString *dataStr = @"[\n  \"82\",\n  \"9F36\",\n  \"9F26\",\n  \"9F02\",\n  \"9F33\",\n  \"9F34\",\n  \"9F1E\",\n  \"9F1A\",\n  \"95\",\n  \"5F2A\",\n  \"9A\",\n  \"9C\",\n  \"9F37\",\n  \"9F10\",\n  \"9F27\",\n  \"9F03\",\n  \"4F\"\n]";
//    NSString *dataStr = @"[\n  \"9F33\",\n  \"95\",\n  \"9F37\",\n  \"9F10\",\n  \"9F26\",\n  \"9F36\",\n  \"82\",\n  \"9F1A\",\n  \"9A\",\n  \"9F27\",\n  \"9C\",\n  \"9F02\",\n  \"5F2A\",\n  \"9F1A\",\n  \"9F03\",\n \"5A\",\n  \"5F34\",\n  \"9F78\",\n ,\n  \"9F77\",\n ,\n  \"9F5C\",\n ,\n  \"9F59\",\n ,\n  \"9F79\",\n ,\n  \"4F\"\n]";
    NSString *dataStr = @"[\n  \"9F33\",\n  \"95\",\n  \"9F37\",\n  \"9F10\",\n  \"9F26\",\n  \"9F36\",\n  \"82\",\n  \"9F1A\",\n  \"9A\",\n  \"9F27\",\n  \"9C\",\n  \"9F02\",\n  \"5F2A\",\n  \"9F1A\",\n  \"9F03\",\n \"5A\",\n  \"5F34\",\n  \"9F78\",\n ,\n  \"9F77\",\n ,\n  \"9F79\",\n ,\n  \"4F\"\n]";
//    NSArray *arr2 = @[@"82",@"9F36",@"9F26",@"9F02",@"9F33",@"9F34",@"9F1E",@"9F1A",@"95",@"5F2A",@"9A",@"9C",@"9F37",@"9F10",@"9F27",@"9F03",@"4F"];
    
    NSDictionary *dic = @{@"dName":@"PBOCDevice",@"action":@"PBOCProcess2",@"arg1":@(slot),@"arg2":@(0),@"param1":param1,@"param2":@"",@"data":dataStr,@"timeOut":@(0)};
    
    NSString *hexadecimalStr = [ZYFDataConversionTool hexadecimalToDictionary:dic];
//    NSLog(@"获取55域（IC卡复位只调用自动检卡)\n %@",hexadecimalStr);
    NSData *data = [ZYFDataConversionTool convertHexStrToData:hexadecimalStr];
    return data;
}

///2.4取消读卡（IC卡复位只调用自动检卡）
+(NSData *)unreadCard {
    
    NSDictionary *dic = @{@"dName":@"PBOCDevice",@"action":@"cancelPBOC",@"arg1":@(0),@"arg2":@(0),@"param1":@"",@"param2":@"",@"data":@"",@"timeOut":@(0)};
    
    NSString *hexadecimalStr = [ZYFDataConversionTool hexadecimalToDictionary:dic];
//    NSLog(@"取消读卡（IC卡复位只调用自动检卡） \n %@",hexadecimalStr);
    NSData *data = [ZYFDataConversionTool convertHexStrToData:hexadecimalStr];
    return data;
}

///3.1 打开扫描头
+(NSData *)scanHeadOpen {
    
    NSDictionary *dic = @{@"dName":@"ScannerDevice",@"action":@"open",@"arg1":@(0),@"arg2":@(0),@"param1":@"",@"param2":@"",@"data":@"",@"timeOut":@(60)};
    NSString *hexadecimalStr = [ZYFDataConversionTool hexadecimalToDictionary:dic];
//    NSLog(@"打开扫描头 \n %@",hexadecimalStr);
    NSData *data = [ZYFDataConversionTool convertHexStrToData:hexadecimalStr];
    return data;
}

///3.2 扫描头扫码
+(NSData *)scanHeadStar {
    
    NSDictionary *dic = @{@"dName":@"ScannerDevice",@"action":@"scan",@"arg1":@(0),@"arg2":@(0),@"param1":@"",@"param2":@"",@"data":@"",@"timeOut":@(60)};
    
    NSString *hexadecimalStr = [ZYFDataConversionTool hexadecimalToDictionary:dic];
//    NSLog(@"扫描头扫码 \n %@",hexadecimalStr);
    NSData *data = [ZYFDataConversionTool convertHexStrToData:hexadecimalStr];
    
    return data;
}

///4.1 打开指纹模块
+(NSData *)fingerprintModuleOpen {
    
    NSDictionary *dic = @{@"dName":@"WELDevice",@"action":@"openFinger",@"arg1":@(0),@"arg2":@(0),@"param1":@"",@"param2":@"",@"data":@"",@"timeOut":@(0)};
    
    NSString *hexadecimalStr = [ZYFDataConversionTool hexadecimalToDictionary:dic];
//    NSLog(@"打开指纹模块 \n %@",hexadecimalStr);
    NSData *data = [ZYFDataConversionTool convertHexStrToData:hexadecimalStr];
    return data;
}

///4.2 读取指纹模版
+(NSData *)fingerprintModuleRead {
    
    NSDictionary *dic = @{@"dName":@"WELDevice",@"action":@"readTemplate",@"arg1":@(0),@"arg2":@(0),@"param1":@"",@"param2":@"",@"data":@"",@"timeOut":@(30)};
    
    NSString *hexadecimalStr = [ZYFDataConversionTool hexadecimalToDictionary:dic];
//    NSLog(@"读取指纹模版\n %@",hexadecimalStr);
    NSData *data = [ZYFDataConversionTool convertHexStrToData:hexadecimalStr];
    return data;
}

///4.3 读取指纹特征
+(NSData *)fingerprintReadCharacteristics {
    
    NSDictionary *dic = @{@"dName":@"WELDevice",@"action":@"readFeature",@"arg1":@(0),@"arg2":@(0),@"param1":@"",@"param2":@"",@"data":@"",@"timeOut":@(30)};
    
    NSString *hexadecimalStr = [ZYFDataConversionTool hexadecimalToDictionary:dic];
//    NSLog(@"读取指纹特征\n %@",hexadecimalStr);
    NSData *data = [ZYFDataConversionTool convertHexStrToData:hexadecimalStr];
    return data;
}

///4.4 检测手指是否按下
+(NSData *)fingerprintWhetherPress {
    
    NSDictionary *dic = @{@"dName":@"WELDevice",@"action":@"checkFinger",@"arg1":@(0),@"arg2":@(0),@"param1":@"",@"param2":@"",@"data":@"",@"timeOut":@(0)};
    
    NSString *hexadecimalStr = [ZYFDataConversionTool hexadecimalToDictionary:dic];
//    NSLog(@"检测手指是否按下\n %@",hexadecimalStr);
    NSData *data = [ZYFDataConversionTool convertHexStrToData:hexadecimalStr];
    return data;
}

///5.1  打开二代证
+(NSData *)idCardOpen {
    
    NSDictionary *dic = @{@"dName":@"IDScanDevice",@"action":@"open",@"arg1":@(0),@"arg2":@(0),@"param1":@"",@"param2":@"",@"data":@"",@"timeOut":@(0)};
    
    NSString *hexadecimalStr = [ZYFDataConversionTool hexadecimalToDictionary:dic];
//    NSLog(@"打开二代证\n %@",hexadecimalStr);
    NSData *data = [ZYFDataConversionTool convertHexStrToData:hexadecimalStr];
    return data;
}

///5.2  扫描身份证
+(NSData *)idCardScan:(NSInteger)timeOut type:(ReadIDCardMessgae)type {

    NSString *arg1 = @"0";
    NSString *arg2 = @"0";
    if (type == ReadIDCardMessgaeInfomation) {
        
        arg1= @"1";
        arg2= @"1";
    }
    
    NSDictionary *dic = @{@"dName":@"IDScanDevice",@"action":@"scan",@"arg1":@(1),@"arg2":@(1),@"param1":@(0),@"param2":@"",@"data":@"",@"timeOut":@(30)};
    
    NSString *hexadecimalStr = [ZYFDataConversionTool hexadecimalToDictionary:dic];
//    NSLog(@"扫描身份证\n %@",hexadecimalStr);
    NSData *data = [ZYFDataConversionTool convertHexStrToData:hexadecimalStr];
    return data;
}

///5.3 关闭二代证模块
+(NSData *)idCardClose {
    
    NSDictionary *dic = @{@"dName":@"IDScanDevice",@"action":@"close",@"arg1":@(0),@"arg2":@(0),@"param1":@"",@"param2":@"",@"data":@"",@"timeOut":@(0)};
    
    NSString *hexadecimalStr = [ZYFDataConversionTool hexadecimalToDictionary:dic];
//    NSLog(@"关闭二代证模块\n %@",hexadecimalStr);
    NSData *data = [ZYFDataConversionTool convertHexStrToData:hexadecimalStr];
    return data;
}

///5.4 退卡
+(NSData *)idCardExit {
    
    NSDictionary *dic = @{@"dName":@"IDScanDevice",@"action":@"eject",@"arg1":@(0),@"arg2":@(0),@"param1":@"",@"param2":@"",@"data":@"",@"timeOut":@(0)};
    
    NSString *hexadecimalStr = [ZYFDataConversionTool hexadecimalToDictionary:dic];
//    NSLog(@"退卡 \n %@",hexadecimalStr);
    NSData *data = [ZYFDataConversionTool convertHexStrToData:hexadecimalStr];
    return data;
}

+ (NSData *)getARQC {
    
    NSDictionary *dic = @{@"dName":@"PBOCDevice",@"action":@"PBOCProcess2"};
    
    NSString *hexadecimalStr = [ZYFDataConversionTool hexadecimalToDictionary:dic];
//    NSLog(@"退卡 \n %@",hexadecimalStr);
    NSData *data = [ZYFDataConversionTool convertHexStrToData:hexadecimalStr];
    return data;
}

@end
